package org.glickr

class FlickrPeople {
    String id
    String nsid // todo figure out the exact difference between is and nsid
    String username
    String realname
    String description
    String gender       // todo enum
    String email
    Boolean isPro
    Boolean isIgnored
    Boolean isContact
    Boolean isFriend
    Boolean isFamily
    Boolean isRevContact
    Boolean isRevFriend
    Boolean isRevFamily
    String location
    String timezoneLabel        // todo translate to Groovy
    String timezoneOffset       // todo translate to Groovy
    Integer photosCount
    String photosFirstDate      // todo translate to Groovy
    String photosFirstDateTaken // todo translate to Groovy
    String mboxSha1sum
    Long iconServer
    Long iconFarm
    String photosUrl
    String profileUrl
    String mobileUrl

    String pathAlias

    private String iconUrl

    private final static iconUrlTemplate = "http://farm<%=iconFarm%>.static.flickr.com/<%=iconServer%>/buddyicons/<%=userId%>.jpg"

    String toString(String join='\n') {
        return this.properties.sort{it.key}.collect{it}.findAll{!['metaClass'].contains(it.key)}.join(join)
    }

    String getIconUrl() {
        if (!this.id || !this.iconFarm || !this.iconServer) { return null }

        // render the icon template
        def engine = new groovy.text.SimpleTemplateEngine()
        def binding = [
            userId      : this.id,
            iconFarm    : this.iconFarm,
            iconServer  : this.iconServer,
        ]
        iconUrl = engine.createTemplate(iconUrlTemplate).make(binding).toString()
        return iconUrl
    }
}

/*
URLs to photo and profile pages use either the user's NSID (the number with the '@' sign in it) or their custom URL (if they've chosen one). You can find their custom URL with a call to flickr.people.getInfo. The NSID version of the URL will always work, regardless of whether they've set up a 'pretty' URL, so you can avoid the API call by simply using the the user ID returned by most photo API calls.
You can then easily build URLs to profiles, photostreams, individual photos or photosets:

http://www.flickr.com/people/{user-id}/ - profile
http://www.flickr.com/photos/{user-id}/ - photostream
http://www.flickr.com/photos/{user-id}/{photo-id} - individual photo
http://www.flickr.com/photos/{user-id}/sets/ - all photosets
http://www.flickr.com/photos/{user-id}/sets/{photoset-id} - single photoset
Other URLs can be constructed similarly. Directing a user to http://www.flickr.com/photos/me/* or http://www.flickr.com/people/me/* will replace the 'me' with their own user ID, if they're logged in (otherwise it will redirect to the latest photos page).

Examples

http://www.flickr.com/photos/12037949754@N01/
http://www.flickr.com/photos/12037949754@N01/155761353/
http://www.flickr.com/photos/12037949754@N01/sets/
http://www.flickr.com/photos/12037949754@N01/sets/72157594162136485/
*/
